<?php

function GetBetContent2($bettype, $numbers)
{
    global $g_betname;
    global $g_bignum;
    global $g_chinayear;
    global $g_colorname;
    $name1 = array("", "单", "双", "大", "小", "红波", "蓝波", "绿波", "合单", "合双");
    $name2 = array("", "1", "2", "3", "4", "5", "6");
    switch ($bettype)
    {
        case 0 :
            return "特码 " . d2($numbers);
        case 1 :
            return "特 " . ( $numbers == 1 ? "单" : "双" );
        case 2 :
            return "特 " . ( $numbers == 1 ? "大" : "小" );
        case 3 :
            return "特 合" . ( $numbers == 1 ? "单" : "双" );
        case 46 :
            $tmpArr = array(1 => "大", 2 => "中", 3 => "小");
            return "特大中小-" . $tmpArr[$numbers];
        case 47 :
            return "特 合" . ( $numbers == 1 ? "大" : "小" );
        case 4 :
            return "正码 " . d2($numbers);
        case 5 :
            return "总 " . ( $numbers == 1 ? "单" : "双" );
        case 6 :
            return "总 " . ( $numbers == 1 ? "大" : "小" );
        case 7 :
        case 8 :
        case 9 :
        case 33 :
        case 10 :
        case 32 :
        case 11 :
        case 29 :
        case 39 :
        case 40 :
        case 41 :
        case 42 :
        case 43 :
        case 44 :
        case 45 :
            $p = explode("|", $numbers);
            $s = $g_betname[$bettype] . "<br>@" . $p[1] . "<br>";
            switch (substr_count($p[3], ","))
            {
                case 14 :
                case 13 :
                case 12 :
                    $s .= substr($p[3], 0, 11) . "<br>" . substr($p[3], 12, 11) . "<br>";
                    $s .= substr($p[3], 25, 11) . "<br>" . substr($p[3], 37, 11) . "<br>";
                    $s .= substr($p[3], 49) . "<br>共" . $p[2] . "组";
                    return $s;
                case 11 :
                case 10 :
                case 9 :
                    $s .= substr($p[3], 0, 11) . "<br>" . substr($p[3], 12, 11) . "<br>";
                    $s .= substr($p[3], 24, 11) . "<br>" . substr($p[3], 37) . "<br>共" . $p[2] . "组";
                    return $s;
                case 8 :
                case 7 :
                    $s .= substr($p[3], 0, 11) . "<br>" . substr($p[3], 12, 11) . "<br>";
                    $s .= substr($p[3],24, 25) . "<br>共" . $p[2] . "组";
                    return $s;
                case 6 :
                case 5 :
                    $s .= substr($p[3], 0, 11) . "<br>" . substr($p[3], 12) . "<br>共" . $p[2] . "组";
                    return $s;
                case 4 :
                    $s .= substr($p[3], 0, 14) . "<br>共" . $p[2] . "组";
                    return $s;
            }
            $s .= $p[3] . "<br>共" . $p[2] . "组";
            return $s;
        case 12 :
            $p = $g_betname[$bettype] . "<br>";
            $p1 = explode(",", $numbers);
            foreach ($p1 as $p2)
            {
                $p3 = explode("_", $p2);
                $p .= "正码" . $name2[$p3[0]] . "" . $name1[$p3[1]] . "<br>@" . $p3[2] . "<br>";
            }
            return $p;
        case 13 :
            return "特 " . $g_colorname[$numbers] . "波";
        case 14 :
            return "特生肖 " . $g_chinayear[$numbers];
        case 15 :
            $p = explode(" ", $numbers);
            return "正码" . $name2[$p[0]] . ( $p[1] == 1 ? " 单" : " 双" );
        case 16 :
            $p = explode(" ", $numbers);
            return "正码" . $name2[$p[0]] . ( $p[1] == 3 ? " 大" : " 小" );
        case 17 :
            $p = explode(" ", $numbers);
            return "正码" . $name2[$p[0]] . $name1[$p[1]];
        case 18 :
            $p0 = "";
            $p1 = "";
            switch ($numbers)
            {
                case 1 :
                case 2 :
                case 3 :
                case 4 :
                    $p0 = 1;
                    $p1 = $numbers;
                    break;
                case 5 :
                case 6 :
                case 7 :
                case 8 :
                    $p0 = 2;
                    $p1 = $numbers - 4;
                    break;
                case 9 :
                case 10 :
                case 11 :
                case 12 :
                    $p0 = 3;
                    $p1 = $numbers - 8;
                    break;
            }
            if ($p1 < 3)
            {
                return "半波 " . $g_colorname[$p0] . ( $p1 == 1 ? "单" : "双" );
            }
            return "半波 " . $g_colorname[$p0] . ( $p1 == 3 ? "大" : "小" );
        case 19 :
            $p1 = explode("|", $numbers);
            $p2 = explode(",", $p1[1]);
            $p3 = explode("_", $p1[0]);
            $n1 = $p3[0];
            $n2 = intval($p3[1]);
            $op = $n2 . "肖 " . ( $n1 == 1 ? "  中" : "不中" ) . "<br>";
            $op .= $g_chinayear[$p2[0]];
            $i = 1;
            while ($i < $n2)
            {
                if ($i == 4 || $i == 8)
                {
                    $op .= "<br>" . $g_chinayear[$p2[$i]];
                }
                else
                {
                    $op .= "," . $g_chinayear[$p2[$i]];
                }
                ++$i;
            }
            return $op;
        case 20 :
            return $numbers == 1 ? "家禽" : "野兽";
        case 21 :
            return "一肖" . $g_chinayear[$numbers];
        case 22 :
            return "尾数" . substr($numbers, 0 - 1);
        case 37 :
            return "一肖" . $g_chinayear[$numbers];
        case 38 :
            return "尾数" . substr($numbers, 0 - 1);
        case 23 :
            $p = explode(" ", $numbers);
            return "正码" . $name2[$p[0]] . ( $p[1] == 8 ? "合单" : "合双" );
        case 24 :
            return "特码 " . d2($numbers);
        case 25 :
            $p = explode(" ", $numbers);
            return "正特" . $g_bignum[$p[0]] . " " . d2($p[1]);
        case 26 :
            $p = explode(" ", $numbers);
            return "正特" . $g_bignum[$p[0]] . " " . d2($p[1]);
        case 27 :
            $p1 = explode("|", $numbers);
            $p2 = explode(",", $p1[1]);
            $op = $g_bignum[$p1[0]] . "肖 ";
            if (3 < $p1[0])
            {
                $op .= "<br>";
            }
            $i = 0;
            while ($i < $p1[0])
            {
                if (0 < $i)
                {
                    $op .= ",";
                }
                $op .= $g_chinayear[$p2[$i]];
                ++$i;
            }
            return $op;
        case 28 :
            return "特尾 " . ( $numbers == 1 ? "大" : "小" );
        case 30 :
            return "合尾 " . ( $numbers == 1 ? "大" : "小" );
        case 31 :
            return "正码 " . d2($numbers);
        case 34 :
            return "总肖 " . ( $numbers == 4 ? "234" : $numbers );
        case 35 :
            return "总肖 " . ( $numbers == 1 ? "单" : "双" );
        case 36 :
            $pp = explode("|", $numbers);
            $p1 = intval(substr($pp[0], 0, 1));
            $p2 = intval(substr($pp[0], 1, 1));
            $p3 = explode(",", $pp[1]);
            $op = $g_bignum[$p1] . "尾" . ( $p2 == 1 ? "中" : "不中" );
            $i = 0;
            while ($i < $p1)
            {
                if (0 < $i)
                {
                    $op .= ",";
                }
                $op .= $p3[$i];
                ++$i;
            }
            return $op;
		case 48:
			$pp = explode("|", $numbers);
			return "四全中 " .$pp[3];
			break;
		case 49:
		case 50:
			return $g_betname[$bettype] .$numbers;
			break;
    }
}

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
//$tmd = new tmd_tpl();
$conf = new Config();
$gametype = intval(getvar("gametype"));
$chkGametype = chkGametype($gametype);
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
//$tmd->assign("account", $curruser['account']);
//$tmd->assign("name", $curruser['name']);
//$tmd->assign("amount", $curruser['amount']);
$diskBetArr = array();
if ($curruser['disk1'] == 1)
{
    array_push($diskBetArr, $g_disk_codeUP['1']);
}
if ($curruser['disk2'] == 1)
{
    array_push($diskBetArr, $g_disk_codeUP['2']);
}
if ($curruser['disk3'] == 1)
{
    array_push($diskBetArr, $g_disk_codeUP['3']);
}
if ($curruser['disk4'] == 1)
{
    array_push($diskBetArr, $g_disk_codeUP['4']);
}
$diskBetStr = implode(" + ", $diskBetArr);
$diskBetStr = $diskBetStr == "" ? "--" : "{$diskBetStr} 盘";
$open = 0;
$round = 0;
$lotto_id = 0;
$rs = getdb("select * from lotto where open>='" . date("Y-m-d") . "' order by open");
if ($rs->eof)
{
   // $tmd->assign("round", "");
}
else
{
    //$tmd->assign("round", d3($rs->f['round']));
    //$tmd->assign("lotto_id", $rs->f['id']);
    $open = $rs->f['open'];
    $round = $rs->f['round'];
    $lotto_id = $rs->f['id'];
    /*if (date("Y-m-d") == $open)
    {
        if ($conf->get("stopbet") <= date("Hi"))
        {
            //$tmd->assign("opendate", "<font color=red><b>截止下注</b></font>");
        }
        else
        {
            //$tmd->assign("opendate", $rs->f['open']);
        }
    }
    else
    {
        //$tmd->assign("opendate", $rs->f['open']);
    }*/
    $rs1 = getdb("!!select amount_6h from k_user_bet where user_id=" . $curruser['id'] . " and lotto_id=" . $lotto_id);
    //$tmd->assign("usedamount", $rs1->f[0] ? $rs1->f[0] : 0 );
    $rs1->close();
    if (0 < $curruser['usemaxamount'] && $curruser['maxamount'] < $curruser['amount'])
    {
        //$tmd->assign("maxamount", "<tr style='color:red'><td>本期限额：</td><td align=right>" . $curruser['maxamount'] . "</td></tr>");
    }
}
$records = 20;
$list = "";
$rs = getdb("select * from bet where user_id=" . $_SESSION['uid'] . " and lotto_id=" . $lotto_id . " and rame in (0,9) order by createtime desc, bettype, numbers LIMIT {$records}");
if ($rs->eof)
{
    //$tmd->assign("list0", "<tr class=td2><td colspan=10 align=center>没有下注资料！</td></tr>");
}
else if ($curruser['enabled'] == 1)
{
    
    $amount = 0;
    $payoff = 0;
    $count = 0;
    while (!$rs->eof)
    {
        $list .= "<tr class=td2 valign=top>";
        $list .= "<td nowrap>" . date("H:i", $rs->f['createtime']) . "</td>";
        $list .= "<td nowrap>" . GetBetContent2($rs->f['bettype'], $rs->f['numbers']) . "</td>";
        $list .= "<td nowrap>" . $g_disk_codeUP[$rs->f['disk']] . "</td>";
        $list .= "<td align=right>" . show_rate($rs->f['bettype'], $rs->f['rate']) . "</td>";
        $list .= "<td align=right>" . $rs->f['amount'] . "</td>";
        $list .= "</tr>";
        $amount += $rs->f['amount'];
        $payoff += $rs->f['payoff'];
        ++$count;
        $rs->movenext();
    }
    
    //$tmd->assign("count", $count);
    //$tmd->assign("sum_amount", $amount);
}
else
{
    //$tmd->assign("list0", "<tr class=td2><td colspan=10 align=center><font color=red>帐号暂停使用！</font></td></tr>");
}
//$tmd->display('member/account');
$ui = new UI(false);
$tpl = new Template_Member();
$tpl->load("main" , "left.tpl");
$tpl->set("disk", $diskBetStr);
$tpl->set("account", $curruser['account']);
$tpl->set("name", $curruser['name']);
$tpl->set("amount", $curruser['amount']);
$tpl->set("balance", floatval($curruser['balance']));
//今日输赢
$sy=0;
foreach($g_gametype_3d as $g)
{
	$sql = "SELECT sum(b1) as c FROM bet".($g['en']!="6h"?"_".$g['en']:"")." WHERE user_id='".$curruser['id']."' and createtime>='".(strtotime(date('Y-m-d',time()-3*3600).' 03:00:00'))."' and createtime<='".time()."'";
	$rs = getdb($sql);
	if ( ! $rs->eof )
		$sy+=floatval($rs->f['c']);
}
if($sy<0)
{
	$tpl->set("sycolor" , 'ff0000');	
	$tpl->set("sy" , '－'.abs(round($sy,2)));		
}
else
{
	$tpl->set("sycolor" , '0000ff');	
	$tpl->set("sy" , round($sy,2));			
}
$tpl->set("tblName",$tblName);
$tpl->set("list0", $list);

switch($gametype)
{
	case '0':
		$tpl->set("tbltype",'<div style="padding-top:0px" id="divBtnOpen_5d">
		<input type="button" class="btn btn-primary" onclick="ShowOpen(0)" style="padding:1px 2px ;text-align:center;width:40px;height:23px;" value="号码">
		<input type="button" class="btn btn-primary" onclick="ShowOpen(1)" style="padding:1px 2px ;text-align:center;width:40px;height:23px;" value="大小">
		<input type="button" class="btn btn-primary" onclick="ShowOpen(2)" style="padding:1px 2px ;text-align:center;width:40px;height:23px;" value="单双">
		<input type="button" class="btn btn-primary" onclick="ShowOpen(3)" style="padding:1px 2px ;text-align:center;width:40px;height:23px;" value="生肖">
		</div>');
		break;	
}
//
include("6h_left.php");
$tpl->set('lotto_list',$table);
//公告
$gonggao = $conf->Get("news");
$tpl->set('gonggao',$gonggao);
$tpl->show("main");